﻿#ifndef _CAMCALCENTER_H_
#define _CAMCALCENTER_H_

#include <QObject>
#include "RobotCmdNode.hpp"

class QSharedMemory;

typedef struct {
    float tgRS[30];
    int lineget_flag_RSL;
    int lineget_flag_RSR;
    int rowReady;
    int DL_state;
} SM_Status;

class CamCalCenter : public QObject {
    Q_OBJECT
public:
    explicit CamCalCenter(int argc, char** argv, QObject* p = nullptr);
    ~CamCalCenter();

    void processPc_proc();
    void processPc();

    void onTgRsReady();

    void call_setSendRsPosData(const QVariantMap& left,
                               const QVariantMap& right,
                               const QString& serial);

    void call_setDLData(double x,
                        double y,
                        double z,
                        double rx,
                        double ry,
                        double rz,
                        quint16 state);

    void call_setRsState(bool b);

    void call_setGenRParam(int missionNum, const QString& serial);

    void call_operate(int nExecStep, const QString& strSerial);

    void call_trigger(int leftT, int rightT);

public:
    std::thread m_threadProcessPc;

private slots:
    void setSendRsPosData(const QVariantMap& left,
                          const QVariantMap& right,
                          const QString& serial);

    void setDlData(double x,
                   double y,
                   double z,
                   double rx,
                   double ry,
                   double rz,
                   quint16 state);

    void setRsState(bool b);

    void setGenRParam(int missionNum, const QString& serial);

    void operate(int nExecStep, const QString& strSerial);

    void trigger(int leftT, int rightT);

private:
    void onGenRReady(int curStep, int totalStep, int operate, const QVariantList &steps);

private:
    void rosSpinThread();
    std::shared_ptr<RobotCmdNode> m_robotCmdNode;
    int argc_;
    char** argv_;
    std::thread m_ros_spin_thread;

private:
    QSharedMemory* m_smImg;
    QSharedMemory* m_smDepth;
    QSharedMemory* m_smBaSend;
    QSharedMemory* m_smStatus;

    bool m_bRunRealsense;

    SM_Status m_dataSMStatus;
};

#endif  // _CAMCALCENTER_H_
